package com.zmn.plat.business.impl.user;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zmn.common.dictionary.GlobalDict;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.plat.business.interfaces.user.UserDeviceBService;
import com.zmn.plat.model.entity.user.UserDevice;
import com.zmn.plat.services.interfaces.user.UserDeviceService;

/**
 * Creator: nowind
 * 
 * @since 2018/7/13 13:56
 */
@Service
public class UserDeviceBServiceImpl implements UserDeviceBService {

    @Resource
    private UserDeviceService userDeviceService;

    @Override
    public Integer insert(UserDevice userDevice) {

        // 设备码为空不允许注册
        if (StringUtil.isBlank(userDevice.getDeviceCode())) {
            return 0;
        }

        // 只注册iOS和Android设备
        if (userDevice.getDeviceType() != GlobalDict.DEVICE_TYPE_IOS && userDevice.getDeviceType() != GlobalDict.DEVICE_TYPE_ANDROID) {
            return 0;
        }

        if (userDevice.getStatus() == 0) {
            userDevice.setStatus(GlobalDict.STATUS_ENABLE);
        }
        if (userDevice.getLastLoginIp() == null) {
            userDevice.setLastLoginIp("");
        }
        if (userDevice.getRegistIp() == null) {
            userDevice.setRegistIp("");
        }

        return userDeviceService.insert(userDevice);
    }

}
